package com.tarry.shop.goods.mq.sender;

import com.tarry.shop.constant.RabbitMQConstant;
import com.tarry.shop.goods.entity.Goods;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *  将商品信息发送到MQ中
 */
@Component
@Slf4j
public class GoodsSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendGoodsInfo(Goods goods){
        log.info("send msg {}",goods);
        rabbitTemplate.convertAndSend(RabbitMQConstant.GOODS_EXCHANGE,
                RabbitMQConstant.GOODS_ROUTING_KEY,
                goods);
    }

}
